<? 

function wowhead_getItemFromWH($id){
	global $sql;
	
	$infos=array("idItem" => $id);
	
	$content=readUrl("http://fr.wowhead.com/item=".$id."&xml");
/*			
echo "<pre>";			
print_r($content);			
echo "</pre>";			
*/
	if(strpos($content,"Item not found!")===false){
	
		$xml = simplexml_load_string($content);
		
		$infos["nom"]=$xml->item->name;
		$infos["nom2"]="<b class='q".$xml->item->quality['id']."'>".$xml->item->name."</b>";
		$infos["tooltip"]=$xml->item->htmlTooltip;
		$infos["icon"]=$xml->item->icon;
		$infos["model"]=$xml->item->icon['displayId'];
		$infos["slot"]=$xml->item->inventorySlot['id'];
		
	}else $infos["nom"]="error";
		
	return $infos;
}

function wowhead_getItem($id){
	global $sql;
	
	$var=$sql->request_single("select * from ".CFG_MYSQL_PREFIX."wowheaditem where idItem=".$id);
	if($var==false){
		$var=wowhead_getItemFromWH($id);
		if($var["nom"]=="error") return false;
		$item=new wowheaditem($var);
		$item->ajouter();
	}else{
		$item=new wowheaditem($var);
	}
	
	return $item;
}